import {createApp} from 'vue';
import {createPinia} from 'pinia';
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import * as ElementPlusIconsVue from '@element-plus/icons-vue';
import App from './App.vue';
import router from './router';
import {usePermissStore} from './store/permiss';
import 'element-plus/dist/index.css';
import './assets/css/icon.css';

const app = createApp(App);
const store = createPinia();
store.use(piniaPluginPersistedstate)
app.use(store);
app.use(router);

// 注册elementplus图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
}
// 自定义权限指令
const permiss = usePermissStore();
app.directive('permiss', {
    mounted(el, binding) {
        console.log('permiss', permiss.userRole, binding.value);
        if (binding.value && !(binding.value.indexOf(permiss.userRole) > -1)) {
            el['hidden'] = true;
        }
    },
});

app.mount('#app');
